package com.zr.eim.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zr.common.annotation.Anonymous;
import com.zr.eim.domain.EimDataPerson;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zr.common.annotation.Log;
import com.zr.common.core.controller.BaseController;
import com.zr.common.core.domain.AjaxResult;
import com.zr.common.enums.BusinessType;
import com.zr.eim.domain.EimAnalysisGpsPoint;
import com.zr.eim.service.IEimAnalysisGpsPointService;
import com.zr.common.utils.poi.ExcelUtil;
import com.zr.common.core.page.TableDataInfo;

/**
 * GPS点位Controller
 * 
 * @author peihang
 * @date 2022-10-21
 */
@RestController
@RequestMapping("/eim/point")
public class EimAnalysisGpsPointController extends BaseController
{
    @Autowired
    private IEimAnalysisGpsPointService eimAnalysisGpsPointService;

    /**
     * 查询GPS点位列表
     */
    @PreAuthorize("@ss.hasPermi('eim:point:list')")
    @GetMapping("/list")
    public TableDataInfo list(EimAnalysisGpsPoint eimAnalysisGpsPoint)
    {
        startPage();
        List<EimAnalysisGpsPoint> list = eimAnalysisGpsPointService.selectEimAnalysisGpsPointList(eimAnalysisGpsPoint);
        return getDataTable(list);
    }

    @PostMapping("/getLastGPs")
    @Anonymous
    public AjaxResult getLastGPs(@RequestBody EimDataPerson eimDataPerson)
    {
        EimAnalysisGpsPoint point = eimAnalysisGpsPointService.selectLastEimAnalysisGps(eimDataPerson);
        return AjaxResult.success(point);
    }

    /**
     * 导出GPS点位列表
     */
    @PreAuthorize("@ss.hasPermi('eim:point:export')")
    @Log(title = "GPS点位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EimAnalysisGpsPoint eimAnalysisGpsPoint)
    {
        List<EimAnalysisGpsPoint> list = eimAnalysisGpsPointService.selectEimAnalysisGpsPointList(eimAnalysisGpsPoint);
        ExcelUtil<EimAnalysisGpsPoint> util = new ExcelUtil<EimAnalysisGpsPoint>(EimAnalysisGpsPoint.class);
        util.exportExcel(response, list, "GPS点位数据");
    }

    /**
     * 获取GPS点位详细信息
     */
    @PreAuthorize("@ss.hasPermi('eim:point:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(eimAnalysisGpsPointService.selectEimAnalysisGpsPointById(id));
    }

    /**
     * 新增GPS点位
     */
    @PreAuthorize("@ss.hasPermi('eim:point:add')")
    @Log(title = "GPS点位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EimAnalysisGpsPoint eimAnalysisGpsPoint)
    {
        return toAjax(eimAnalysisGpsPointService.insertEimAnalysisGpsPoint(eimAnalysisGpsPoint));
    }

    /**
     * 修改GPS点位
     */
    @PreAuthorize("@ss.hasPermi('eim:point:edit')")
    @Log(title = "GPS点位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EimAnalysisGpsPoint eimAnalysisGpsPoint)
    {
        return toAjax(eimAnalysisGpsPointService.updateEimAnalysisGpsPoint(eimAnalysisGpsPoint));
    }

    /**
     * 删除GPS点位
     */
    @PreAuthorize("@ss.hasPermi('eim:point:remove')")
    @Log(title = "GPS点位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(eimAnalysisGpsPointService.deleteEimAnalysisGpsPointByIds(ids));
    }
}
